FROM openjdk:8

ENV ATLASSIAN_INSTALL_DIR=/opt/atlassian
ENV ATLASSIAN_HOME=/var/lib/atlassian

RUN set -eux; \
        apt-get update; \
        apt-get install -y --no-install-recommends \
                gosu \
        ; \
        rm -rf /var/lib/apt/lists/*; \
        gosu nobody true

# Create atlassian system user
RUN set -eux; \
        groupadd --gid 1000 --system atlassian; \
        useradd --uid 1000 --system --home-dir "${ATLASSIAN_HOME}" --gid atlassian atlassian; \
        mkdir -p "${ATLASSIAN_INSTALL_DIR}" "${ATLASSIAN_HOME}" /docker-entrypoint-init.d; \
        chown -fR atlassian:atlassian "${ATLASSIAN_INSTALL_DIR}" "${ATLASSIAN_HOME}";

WORKDIR ${ATLASSIAN_HOME}

ADD atlassian-agent.jar .
ENV JAVA_OPTS=-javaagent:${ATLASSIAN_HOME}/atlassian-agent.jar

COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
